<?php
namespace Home\Controller;
class MessagesController extends CommonController {

public function _initialize()
{
		$this->Is_login();        //检测用户登录信息,如果错误直接返回错误,终止程序
		$this->Is_power("message");        //检测用户权限,如果错误直接返回错误,终止程序
		$this->assign('heardadminData',session('heardadminData'));
}

//创建订单
public function messages_add()
{
		$this->display();
}

public function add_messages()
{
	// p($_POST);exit();

	$title = I('post.title');
	$article = I('post.article');
	if (empty($title)||empty($article)) {
			$this->error('参数错误',"",1);
	}
	$content = $this->PostOss($article);
	if (!$content) {
		$this->error('文章错误',"",1);
	}
	$message = D("message");
	if (!$message->create()){//自动验证
		$this->error('参数错误',"",1);
	}else{
		$now_time = time();
		$data = $message->create(); // 保存生成的数据对象
		$data['title'] = $title;
		$data['time'] = $now_time;
		$data['content'] = $content;
		$result = $message->add($data);
		$this->adminlog("创建消息");
		$this->success('创建成功',"/Home/Messages/messages_list",1);
	}

}

//订单列表
public function messages_list()
{
		$db_message = M("message");
		$count = $db_message->order('id desc')->count();
		$p = getpage($count, 20);
		$messageinfo = $db_message->order('id desc')->limit($p->firstRow, $p->listRows)->select();
		$this->assign('messageinfo',$messageinfo);
		$this->assign('page', $p->show());
		$this->display();
}

//订单详情
public function messages_edit()
{
		$mid = I('get.mid');
		$messagedata = M('message')->where(array("id"=>$mid))->find();
		$this->articledata = $this->GetOss($messagedata['content']);
		// p($articledata);exit();
		$this->assign('messagedata',$messagedata);
		$this->display();
}



}